package cn.qidisoft.edu.hzjt.service.zyc.impl;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.zyc.ScientificNoticeAttMapper;
import cn.qidisoft.edu.hzjt.model.zyc.ScientificNotice;
import cn.qidisoft.edu.hzjt.model.zyc.ScientificNoticeAtt;
import cn.qidisoft.edu.hzjt.service.zyc.IScientificNoticeAttService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScientificNoticeAttServiceImpl implements IScientificNoticeAttService {

    protected static final LoggerAdapter LOGGER = LoggerAdapterFactory
            .getLogger(LogType.HZJT_LOGGER.val);

    @Autowired
    ScientificNoticeAttMapper scientificNoticeAttMapper;

    @Override
    public List<ScientificNoticeAtt> queryList(ScientificNoticeAtt schoolMagazineAtt) {
        return scientificNoticeAttMapper.queryList(schoolMagazineAtt);
    }

    @Override
    public PaginationBean<ScientificNoticeAtt> queryPageList(ScientificNoticeAtt data, Page page) {
        try {
            int c = scientificNoticeAttMapper.queryPageListcount(data);
            int totalRecords = c;
            PaginationBean<ScientificNoticeAtt> pageHolder = new PaginationBean<>(page, totalRecords);
            List<ScientificNoticeAtt> resultList = scientificNoticeAttMapper.queryPageList(data,
                            new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                    this.getClass().getName(),
                    ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                    e);
        }
    }

    @Override
    public ScientificNoticeAtt queryByPK(ScientificNoticeAtt record) {
        return scientificNoticeAttMapper.queryByPK(record);
    }

    @Override
    public String insert(ScientificNoticeAtt record) {
        scientificNoticeAttMapper.insert(record);
        return "";
    }

    @Override
    public void batchInserts(List<ScientificNoticeAtt> records) {
        scientificNoticeAttMapper.batchInserts(records);
    }

    @Override
    public int update(ScientificNoticeAtt record) {
        scientificNoticeAttMapper.update(record);
        return 0;
    }

    @Override
    public int delete(ScientificNoticeAtt record) {
        scientificNoticeAttMapper.delete(record);
        return 0;
    }

    @Override
    public int validation(ScientificNoticeAtt record) {
        return scientificNoticeAttMapper.validation(record);
    }

	@Override
	public List<ScientificNoticeAtt> getPlanningAtt(ScientificNotice sMagazine) {
		
		return scientificNoticeAttMapper.getPlanningAtt(sMagazine);
	}

	@Override
	public ScientificNoticeAtt queryByFileId(ScientificNoticeAtt attEntity) {
		return scientificNoticeAttMapper.queryByFileId(attEntity);
	}

	@Override
	public void deleteAccessory(ScientificNoticeAtt attEntity) {
		
		scientificNoticeAttMapper.deleteAccessory(attEntity);
		
	}
}
